﻿using Sdg.Domain.BizObj;
using Sdg.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data.SqlClient;


namespace Sdg.Dal.Repositories
{
    internal class TableRepository : Repository<TableSettings>, ITableRepository
    {

        public IEnumerable<TableSettings> GetDbTables(string nameFilter)
        {

            var tables = this.Select<TableSettings>("select Name, object_id as ObjectId from sys.tables where type='U' order by name", null);


            return tables;
        }

        public IEnumerable<TableColumn> GetTableColumns(int tableId)
        {
            var cmd = _connection.CreateCommand();
            cmd.CommandText = "select top 1 * from tics where 1=1";
            cmd.CommandType = System.Data.CommandType.Text;
            _connection.Open();
            var res = cmd.ExecuteReader();
            object[] rows = new object[100];
            res.Read();
            res.GetValues(rows);
            //res.GetSchemaTable().Columns[0].DataType
            return null;
        }

        public object GetColumns()
        {
            return _connection.Query("select top 1 * from tics");
        }
    }
}
